package org.loong.crypto.service.core.provider.impl;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import org.loong.crypto.core.algorithm.KeyPairAlgorithm;
import org.loong.crypto.service.core.context.CryptoContext;
import org.loong.crypto.service.core.provider.KeyPairGeneratorProvider;

/**
 * The base abstract class for key pair generator.
 * 
 * <p>
 * Supports the following algorithms:
 *
 * <ul>
 * <li>{@link org.loong.crypto.core.algorithm.KeyPairAlgorithm#DSA}
 * <li>{@link org.loong.crypto.core.algorithm.KeyPairAlgorithm#ECDSA}
 * <li>{@link org.loong.crypto.core.algorithm.KeyPairAlgorithm#RSA}
 * <li>{@link org.loong.crypto.core.algorithm.KeyPairAlgorithm#SM2}
 * </ul>
 */
public abstract class BaseKeyPairGeneratorProvider implements KeyPairGeneratorProvider {

    /**
     * The supported key pair generator algorithms by the KeyPairGenerator provider class.
     */
    public static final Set<KeyPairAlgorithm> SUPPORTED_ALGORITHMS;

    /**
     * The cryptoContext.
     */
    private CryptoContext cryptoContext;
    
    static {
        Set<KeyPairAlgorithm> algs = new LinkedHashSet<>();
        algs.add(KeyPairAlgorithm.DSA);
        algs.add(KeyPairAlgorithm.ECDSA);
        algs.add(KeyPairAlgorithm.RSA);
        algs.add(KeyPairAlgorithm.SM2);
        SUPPORTED_ALGORITHMS = Collections.unmodifiableSet(algs);
    }

    @Override
    public Set<KeyPairAlgorithm> supportedKeyPairAlgorithms() {
        return SUPPORTED_ALGORITHMS;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public <T extends CryptoContext> T getCryptoContext() {
        return (T) cryptoContext;
    }

    @Override
    public void setCryptoContext(CryptoContext cryptoContext) {
        this.cryptoContext = cryptoContext;
    }
}
